package ai.zixing.factory.factory_method.controller;

import ai.zixing.factory.factory_method.factory.FreeGoodsFactoryMap;
import ai.zixing.factory.factory_method.factory.FreeGoodsFactory;
import ai.zixing.factory.simple_factory.entity.AwardInfo;
import ai.zixing.factory.simple_factory.entity.ResponseResult;
import ai.zixing.factory.simple_factory.service.IFreeGoods;

public class DeliverController {
    /**
     * 按照类型的不同发放商品
     */
    public ResponseResult awardToUser(AwardInfo awardInfo){

//        FreeGoodsFactory freeGoodsFactory = null;
//        if(awardInfo.getAwardTypes() == 1){
//            freeGoodsFactory = new DiscountFreeGoodsFactory();
//        }else if(awardInfo.getAwardTypes() == 2){
//            freeGoodsFactory = new SmallGiftFreeGoodsFactory();
//        }
//        IFreeGoods freeGoods = freeGoodsFactory.getInstance();

        //
        FreeGoodsFactory goodsFactory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardTypes());
        IFreeGoods freeGoods = goodsFactory.getInstance();

        System.out.println("=====工厂方法模式========");
        ResponseResult result = freeGoods.sendFreeGoods(awardInfo);

        return result;
    }
}
